package com.hopes.bizz.enforcement.hid.controller;

import com.hopes.bizz.enforcement.common.constant.FlowConstant;
import com.hopes.bizz.enforcement.common.constant.HidDicConstant;
import com.hopes.bizz.enforcement.hid.entity.RiskHidCheckTaskEntity;
import com.hopes.bizz.enforcement.hid.service.RiskHidCheckTaskService;
import com.hopes.bizz.enforcement.hid.service.RiskHidHiddenDangerService;
import com.hopes.bizz.enforcement.hid.vo.AppHidCount;
import com.hopes.boss.common.core.util.R;
import com.hopes.boss.common.security.util.SecurityUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: ljh
 * @create: 2024/2/1
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/statistics")
@Tag(description = "statistics", name = "统计接口")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class BaseStatisticsController {


    private final RiskHidCheckTaskService riskHidCheckTaskService;
    private final RiskHidHiddenDangerService hidHiddenDangerService;

    /**
     * 执法任务未完成个数统计
     */
    @Operation(summary = "执法任务未完成个数统计", description = "执法任务未完成个数统计")
    @GetMapping("/checkTask")
    public R getCheckTaskToDoCount() {
        return R.ok(riskHidCheckTaskService.lambdaQuery()
                .eq(RiskHidCheckTaskEntity::getTaskStatus, HidDicConstant.RISK_HID_CHECKLIST_TASK_STATUS_TODO)
                .eq(RiskHidCheckTaskEntity::getCheckPerson, SecurityUtils.getUserId())
                .count());
    }


    /**
     * 执法管理待确认个数
     */
    @Operation(summary = "执法管理待确认个数", description = "执法管理待确认个数")
    @GetMapping("/hidCount")
    public R<AppHidCount> getHidCount() {
        AppHidCount appHidCount = new AppHidCount();
        String flowKey = FlowConstant.HIDDEN_DANGER_PARK;
        appHidCount.setWaitConfirm(hidHiddenDangerService.countTodo(HidDicConstant.HID_DANGER_STATUS_WAIT_CONFIRM.toString(), flowKey));
        String taskKey = "";
        if (SecurityUtils.isGroup()) {
            taskKey = HidDicConstant.HID_DANGER_WAIT_RECTIFICATION_PARK.toString();
        } else if (SecurityUtils.isCompany()) {
            taskKey = HidDicConstant.HID_DANGER_WAIT_RECTIFICATION.toString();
        }
        appHidCount.setWaitRectification(hidHiddenDangerService.countTodo(taskKey,flowKey));
        appHidCount.setWaitAcceptance(hidHiddenDangerService.countTodo(HidDicConstant.HID_DANGER_STATUS_WAIT_ACCEPTANCE.toString(), flowKey));
        return R.ok(appHidCount);
    }

}
